$(document).ready(function () {	

		$(".lang").live("click", function (event, ui) {
		    //Chat.roster_click(this);
		    var langName = $(this).attr('alt');
		   
		    var site_url = $('#site_url').attr('alt');
		    var current_url = $('#current_url').attr('alt');
		    //alert(site_url + "/Language/" + langName);
		    $.ajax({
	  			type: "POST",
	  			url: site_url + "/language/index/" + langName,
	  			/*data: {},
	  			// data: { sender: _sender, receiver: _receiver, message: _message, senderId:$("#userId").val(), createdDate:_createdDate, chatName:_chatName, state:_state, groupId:_groupId, parentId:_parentId, companyId:_companyId},
	  			dataType: "json",
	  			async: false, 
	            success: function(msg){
	  				//window.location = current_url + "/" + langName;
	  				alert("sucess.");
	  				return;
	                if(msg.error == false){
	                    groupEmailId = msg.groupId;
						//alert( groupEmailId + " success: " + msg.sql);
						setGroupId(_receiver, groupEmailId);
						setCreatedDate(_receiver, msg.createdDate);
						//setParentId(_receiver, msg.parentId);
						//return groupEmailId;
						//alert(msg.createdDate + " ..." + msg.sql);
					}
					else{
						alert(" Error: " + msg.message);
					}
	            },
	            error : function(XMLHttpRequest, textStatus, errorThrown) {
	                // $('#waiting').hide(500);
	                // $('#message').removeClass().addClass('error').text('There was an error.').show(500);
	                // $('#demoForm').show(500);
	                alert( "Error: " + textStatus.toString());
	            }
	            */
	           
			}).done(function( msg ) {
	  			//alert( "Data Saved: " + msg );
				window.location = current_url;
			});
		    
		});
		
		// update cart:
		$("#update_cart").live("click", function (event, ui) {
			$("#form_cart").submit();
		});
		
		$("#btn_view_cart").live("click", function (event, ui) {
			 $(window.location).attr('href', $('#site_url').attr('alt') + '/cart');
		});
		
		$("#btn_checkout").live("click", function (event, ui) {
			 $(window.location).attr('href', $('#site_url').attr('alt') + '/checkout');
		});
		
		$("#btn_login").live("click", function (event, ui) {
			//alert("clcik login.");
			$("#login_form").submit();
		});
		
		$("#btn_create_account").live("click", function (event, ui) {
			$(window.location).attr('href', $('#site_url').attr('alt') + '/customer/add');
		});
		
		
		$("#payment_method").live("click", function (event, ui) {
			var payment = $(this).val();
			//alert(payment);
			
			if(payment == 'Credit Card')
				$('#t_creditcard').css('display', 'inline-block');
				// $('#t_creditcard').attr('display', 'block');
			else
				//$('#t_creditcard').attr('display', 'none');
				$('#t_creditcard').css('display', 'none');
			
			// $(window.location).attr('href', $('#site_url').attr('alt') + '/checkout');
		});
		
		/*
		$('#clickme').click(function() {
			  $('#book').hide('slow', function() {
			    alert('Animation complete.');
			  });
		});
		*/
		
		$("#btn_create_order").live("click", function (event, ui) {
			var site_url = $('#site_url').attr('alt');
		    var current_url = $('#current_url').attr('alt');
		    //alert(site_url + "/Language/" + langName);
		    //alert(site_url);
		    //return;
		    $.ajax({
	  			type: "POST",
	  			url: site_url + "/member/orders/create",
	  			//data: {},
	  			// data: { sender: _sender, receiver: _receiver, message: _message, senderId:$("#userId").val(), createdDate:_createdDate, chatName:_chatName, state:_state, groupId:_groupId, parentId:_parentId, companyId:_companyId},
	  			dataType: "json",
	  			//async: false, 
	            success: function(msg){
	  				//window.location = current_url + "/" + langName;
		    		$("#invoice").val(msg.orderId);
		    		$("#custom").val(msg.custom); 
		    		$("#cancel_return").val('http://www.angelbeautycali.com/member/orders/cancel/' + msg.custom); 
		    		
	  				$('#frmPayment').submit();
	  				
	  				return;

	                if(msg.error == false){
	                    //groupEmailId = msg.groupId;
						alert( groupEmailId + " success: " + msg.orderId);
						//setGroupId(_receiver, groupEmailId);
						//setCreatedDate(_receiver, msg.createdDate);
						//setParentId(_receiver, msg.parentId);
						//return groupEmailId;
						//alert(msg.createdDate + " ..." + msg.sql);
					}
					else{
						alert(" Error: " + msg.message);
					}
	            },
	            error : function(XMLHttpRequest, textStatus, errorThrown) {
	                // $('#waiting').hide(500);
	                // $('#message').removeClass().addClass('error').text('There was an error.').show(500);
	                // $('#demoForm').show(500);
	                alert( "Error: " + textStatus.toString());
	            }
     
			}).done(function( msg ) {
	  			//alert( "Data Saved: " + msg );
				//window.location = current_url;
			});
		});
});

function checkPayment(){
	//$('#').hide();
}

function submitCart(){
	//document.forms["form_cart"].submit();
}
